function EventTarget() {
    this._events = {}
}
EventTarget.prototype = {
    /**
     * @note 支持一次绑定过个事件，通过空格分隔
     * */
    on(type, hdr) {
        let types = type.split(' ');
        types.forEach(type => {
            !!this._events.hasOwnProperty(type) || (this._events[type] = []);
            this._events[type].push(hdr);
        });
    },
    /**
     * @note 触发不能支持多个，因为要传递事件对象 event
     * */
    emit(event) {
        if(this._events[event.type] instanceof Array) {
            for(let i = 0, len = this._events[event.type].length; i < len; i++) {
                this._events[event.type][i](event);
            }
        }
    },
    /**
     * @note 支持一次卸载过个事件，通过空格分隔
     * */
    off(type, hdr) {
        let types = type.split(' ');
        types.forEach(type => {
            if(this._events[type] instanceof Array) {
                for(let i = this._events[type].length - 1; i >= 0; i--) {
                    if(this._events[type][i] == hdr) {
                        this._events[type].splice(i, 1);
                    }
                }
            }
        });
    }
}
EventTarget.prototype.constructor = EventTarget;

export default EventTarget;